<?php

class News extends Controller {
	
	function News()
	{
		parent::Controller();	
	}
	
	function index()
	{
		$this->load->helper('form');
		$this->load->model('News_Model');
		$this->load->database();

		$data['title'] = "GCMS >> Latest News";
		$data['heading'] = "Latest News";
		$data['style'] = base_url().'system/application/views/content.css';
		
		$data['header'] = $this->load->view('header', $data, true);
		$data['footer'] = $this->load->view('footer', $data, true);
		$this->_login_check($data, 'news_view');

	}
	
	function create()
	{
		$this->load->model('News_Model');
		
		$this->News_Model->insert_entry();
		redirect('/news', 'refresh');
	}
	
	function edit()
	{
		$this->load->helper('form');
		$this->load->database();

		$data['title'] = "GCMS >> Latest News >> Edit";
		$data['heading'] = "Latest News >> Edit";
		$data['style'] = base_url().'system/application/views/content.css';
		$data['id'] = $this->uri->segment(3);
		
		$data['header'] = $this->load->view('header', $data, true);
		$data['footer'] = $this->load->view('footer', $data, true);
		$this->_login_check($data, 'news_edit_view');

	}
	
	function edit2()
	{
		$this->load->model('News_Model');

		$this->News_Model->update_entry();
		redirect('/news', 'refresh');
	}
	
	function delete()
	{
		$this->load->model('News_Model');

		$this->News_Model->delete_entry($this->uri->segment(3));
		redirect('/news', 'refresh');
	}
	
	function _login_check($data, $dest)
	{
		$this->load->library('session');
		$this->load->library('validation');
		$logged_in = $this->session->userdata('logged_in');
		if(!$logged_in){
			$this->load->view('login', $data);
		} else {
			$this->load->view($dest, $data);
		}
	}
	
}
?>